/**
* BISMILLAHIR RAHMANIR RAHIM ("in the name of God, Most Gracious, Most Merciful")
* time start: 2024-02-15 21:12:54
* time end : 2024-02-15 21:55:14
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
void somadan() {
ll n = 1,k;
cin >> n>>k;
ll temp = 2*n -2;
ll ans =0;
if(2*temp >= k) {
if(k%2) {
cout << k/2 +1 << endl;
}
else {
cout << k/2 << endl;
}
}
else {
cout << k - temp << endl;
}
}
int main(void) {
ll t = 1;
cin >> t;
while(t--) somadan();
}
1149A - Prefix Sum Primes | 277A - Learning Languages |
769A - Year of University Entrance | 1738A - Glory Addicts |
1738C - Even Number Addicts | 1064B - Equations of Mathematical Magic |
384A - Coder | 1738B - Prefix Sum Addicts |
1352D - Alice Bob and Candies | 1316D - Nash Matrix |
1548B - Integers Have Friends | 348A - Mafia |
315B - Sereja and Array | 204A - Little Elephant and Interval |
385B - Bear and Strings | 114C - Grammar Lessons |
1427A - Avoiding Zero | 583A - Asphalting Roads |
1358B - Maria Breaks the Self-isolation | 828A - Restaurant Tables |
1735A - Working Week | 1735D - Meta-set |
1735B - Tea with Tangerines | 1735C - Phase Shift |
1321C - Remove Adjacent | 281B - Nearest Fraction |
1043A - Elections | 1598C - Delete Two Elements |
1400C - Binary String Reconstruction | 1734D - Slime Escape |